package org.example.com.controller;

import jakarta.annotation.Resource;
import org.example.com.Bean.Book;
import org.example.com.service.BookService;
import org.example.com.util.JsonResult;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookService bookService;
    @GetMapping
    public JsonResult findAll() {
        return bookService.findBook();
    }
    @GetMapping("/page/{page}")
    public JsonResult find(@PathVariable("page") int page){
        return bookService.findBook(page);
    }
    @GetMapping("/id/{id}")
    public JsonResult find(@PathVariable("id") String id){
        return bookService.findById(id);
    }
    @GetMapping("/search/{name}/{page}")
    public JsonResult find(@PathVariable("name") String name, @PathVariable("page") int page){
        return bookService.findByBookName(name,page);
    }
    @PutMapping("/change_status/{id}/{status}")
    public JsonResult update(@PathVariable("id") String id,@PathVariable("status") int status){
        return bookService.updateBookStatus(id,status);
    }
    @PostMapping
    public JsonResult saveBook(Book book){
        return bookService.saveBook(book);
    }
    @DeleteMapping("/{id}")
    public JsonResult DeleteBook(@PathVariable("id") String id){
        return bookService.deleteBook(id);
    }
    @PutMapping
    public JsonResult updateBook(Book book){
        return bookService.updateBook(book);
    }
}
